/**   
 * Copyright 2011 COMERE Harold
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package etrl.shaders;

/**
 * \class UniformVariable 
 * \brief Specialized Variable describing an uniform variable
 * 
 * @author harold
 * 
 */
class UniformVariable extends Variable
{
	/**
	 * \brief Initializes the uniform variable
	 * @param name Name of the variable
	 * @param type Type of the variable
	 * @param forwardMode Forward mode applied to the variable
	 * @param elementCount Element count of the variable, if > 1 the variable is an array
	 */
	public UniformVariable(String name, GLSLType type, VariableForwardMode forwardMode, int elementCount)
	{
		super(name, type, forwardMode, false, false, elementCount);
	}

	/**
	 * {@inheritDoc}
	 */
	public String getDeclarationInVertexShader()
	{
		String declaration = new String("");

		switch (_forwardMode)
		{
		case VERTEX_ONLY:
		case VERTEX_AND_FRAGMENT:
			declaration += "uniform " + _type.asString() + " " + _name;

			if (_array)
			{
				declaration += "[" + new String("" + _arraySize) + "]";
			}

			declaration += ";\n";
			break;

		case FRAGMENT_ONLY:
			// no declaration in vertex shader
			break;
		}

		return declaration;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getDeclarationInFragmentShader()
	{
		String declaration = new String("");

		switch (_forwardMode)
		{
		case VERTEX_ONLY:
			// No declaration in fragment shader
			break;

		case FRAGMENT_ONLY:
		case VERTEX_AND_FRAGMENT:
			declaration += "uniform " + _type.asString() + " " + _name;

			if (_array)
			{
				declaration += "[" + new String("" + _arraySize) + "]";
			}

			declaration += ";\n";
			break;
		}

		return declaration;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getInitialization()
	{
		return "";
	}

	/**
	 * {@inheritDoc}
	 */
	public String getBindingId()
	{
		return "";
	}

	/**
	 * {@inheritDoc}
	 */
	public String nameWithPrefix(ShaderStage stage)
	{
		return _name;
	}

}
